'use strict';

/**
 * @ngdoc overview
 * @name passwordAgentApp
 * @description
 * # passwordAgentApp
 *
 * Main module of the application.
 */
angular
  .module('passwordAgentApp', [
    'ngAnimate',
    'ngAria',
    'ngCookies',
    'ngMessages',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch',
    'ui.router',
    'ui.bootstrap'
  ])
  .run(['$rootScope', '$state', '$stateParams', '$location',
    function ($rootScope, $state, $stateParams, $location) {
      //$rootScope.changeView = function (view) {
      //  $location.path(view);
      //}
      console.log($rootScope);
      console.log($location);
      console.log($state);
      console.log($stateParams);
      $rootScope.changeView = function (view) {
        $location.path(view);
        console.log(view);
      }


      $rootScope.$state = $state;
      $rootScope.$stateParams = $stateParams;

    }])
  .config(
  ['$stateProvider', '$urlRouterProvider',
    //['$stateProvider', '$routeProvider',
    function ($stateProvider, $urlRouterProvider) {
      //$routeProvider.when("", "/home");
      //$routeProvider.when("/", "/home");
      $urlRouterProvider
        //.when('/home', 'views/home.html')
        //.when('/passwordAgent', '/passwordAgent')
        //.when('/about', 'about.html')
        .otherwise('/index');
      //$stateProvider.decorator('views', function (state, parent) {
      //  var result = {},
      //    views = parent(state);
      //
      //  angular.forEach(views, function (config, name) {
      //    var autoName = (state.name + '.' + name).replace('.', '/');
      //    config.templateUrl = config.templateUrl || '/partials/' + autoName + '.html';
      //    result[name] = config;
      //    console.log(config);
      //  });
      //  return result;
      //});
      $stateProvider
        .state('site', {
          url: '/',
          //templateUrl: 'views/home.html',
          abstract: true,
          template: '<div ui-view></div>',
          onEnter: function () {
            console.log("enter site");
          }

        })
        .state('site.index', {
          url: 'index',
          templateUrl: 'views/home.html',
          controller: 'MainCtrl',
          onEnter: function () {
            console.log("enter MainCtrl");
          }

        })
        .state('site.passwordAgent', {
          url: 'passwordAgent',
          templateUrl: 'views/password-agent.html',
          controller: 'passwordAgentCtrl',
          onEnter: function () {
            console.log("enter passwordAgentCtrl");
          }

        })
        .state('site.about', {
          url: 'about',
          templateUrl: 'views/about.html',
          controller: 'AboutCtrl',
          onEnter: function () {
            console.log("enter AboutCtrl");
          }
        })
    }]);
